$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'deptmanage/salaryinfo/list',
        datatype: "json",
        colModel: [			
			{ label: 'salaryNo', name: 'salaryNo', index: 'salary_no', width: 50, key: true },
			{ label: '员工序号', name: 'userseq', index: 'userseq', width: 80 }, 			
			{ label: '当前税前工资', name: 'preTaxSalary', index: 'pre_tax_salary', width: 80 },
			{ label: '当前税后工资', name: 'afterTaxSalary', index: 'after_tax_salary', width: 80 },
			{ label: '社保扣除（个人）金额', name: 'socialInsuranceReducePersonMoney', index: 'social_insurance_reduce_person_money', width: 80 }, 			
			{ label: '社保基数', name: 'socialInsuranceBase', index: 'social_insurance_base', width: 80 },
			{ label: '社保扣除（企业）金额', name: 'socialInsuranceReduceCompanyMoney', index: 'social_insurance_reduce_company_money', width: 80 },
			{ label: '公积金缴存比例', name: 'depositRatio', index: 'deposit_ratio', width: 80 },
			{ label: '公积金基数', name: 'accumulationFundBase', index: 'accumulation_fund_base', width: 80 },
			{ label: '考勤天数', name: 'checkDay', index: 'check_day', width: 80 },
			{ label: '每日薪资', name: 'salaryDay', index: 'salary_day', width: 80 },
			{ label: '创建日期', name: 'createDate', index: 'create_date', width: 80 }, 			
			{ label: '创建人', name: 'createUser', index: 'create_user', width: 80 }, 			
			{ label: '修改日期', name: 'updateDate', index: 'update_date', width: 80 }, 			
			{ label: '修改人', name: 'updateUser', index: 'update_user', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		salaryInfo: {},
		q : {
			key : null
		},
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.salaryInfo = {};
		},
		update: function (event) {
			var salaryNo = getSelectedRow();
			if(salaryNo == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(salaryNo)
		},
		saveOrUpdate: function (event) {
			var url = vm.salaryInfo.salaryNo == null ? "deptmanage/salaryinfo/save" : "deptmanage/salaryinfo/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.salaryInfo),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var salaryNos = getSelectedRows();
			if(salaryNos == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "deptmanage/salaryinfo/delete",
                    contentType: "application/json",
				    data: JSON.stringify(salaryNos),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(salaryNo){
			$.get(baseURL + "deptmanage/salaryinfo/info/"+salaryNo, function(r){
                vm.salaryInfo = r.salaryInfo;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData : {
                    'key' : vm.q.key
                },
                page:page
            }).trigger("reloadGrid");
		}
	}
});